<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<link rel="stylesheet" href="css/bootstrap-3.3.7/css/bootstrap.min.css" />
<link rel="stylesheet" href="css/register.css" />
<link rel="stylesheet" href="css/listCommon.css" />
<link rel="stylesheet" href="css/evaluation.css" />
<style>
    .modal-backdrop {
        position: inherit;
    }
    .btn.focus, .btn:focus, .btn:hover {
        color: #333;
    }
</style>
<jsp:include page="../common/nav.jsp"></jsp:include>
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="purchaseOrder">
        <input id="id" name="id" type="hidden" value="${requestScope.purchasingRequisition.id}" disabled>
        <div class="formTitle">基本信息</div>
        <div class="trackInfomation">
            <div class="row">
                <div class="col-md-6">
                    <div class="form-group">
                        <span>*</span>
                        <label>编号：</label>
                        <input id="code" name="code" type="text" class="form-control" placeholder="请输入编号" value="${requestScope.purchasingAudit.code}" disabled>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-group">
                        <span>*</span>
                        <label class="control-label" for="type">计划类型</label>
                        <select class="form-control" name="type" id="type" disabled>
                            <option value="" selected="selected">请选择计划类型</option>
                            <c:forEach items="${requestScope.typeMap}" var="typeMap">
                                <c:if test="${requestScope.purchasingAudit.type == typeMap.key}">
                                    <option value="${typeMap.key}" selected>${typeMap.value}</option>
                                </c:if>
                                <c:if test="${requestScope.purchasingAudit.type != typeMap.key}">
                                    <option value="${typeMap.key}">${typeMap.value}</option>
                                </c:if>
                            </c:forEach>
                        </select>
                    </div>
                </div>
            </div>
            <div class="formTitle">
                申请信息
            </div>
            <div class="tableWrap">
                <table class="table table-bordered">
                    <thead id="subBody">
                        <tr>
                            <th width="5%">序号</th>
                            <th>编号</th>
                            <th>标题</th>
                            <th>采购类型</th>
                            <th>公司代码</th>
                            <th>部门名称</th>
                            <th>申请人</th>
                            <th>申请时间</th>
                            <th>期望交货时间</th>
                            <th>采购原因</th>
                            <th>状态</th>
                            <th>附言</th>
                            <th width="10%">操作</th>
                        </tr>
                        <c:if test="${empty requestScope.purchasingAudit.subs}">
                            <tr id="nothing">
                                <td colspan="13" style="color: #bbbbbb">无申请信息</td>
                            </tr>
                        </c:if>
                        <c:if test="${not empty requestScope.purchasingAudit.subs}">
                            <c:forEach items="${requestScope.purchasingAudit.subs}" var="data" varStatus="index">
                                <tr>
                                    <td>${index.count}</td>
                                    <td>${data.code}</td>
                                    <td>${data.title}</td>
                                    <td>${requestScope.subTypeMap[data.type]}</td>
                                    <td>${data.companyCode.concat(' - '.concat(data.companyName))}</td>
                                    <td>${data.departmentName}</td>
                                    <td>${data.createUserName}</td>
                                    <td><fmt:formatDate value="${data.createTime}" pattern="yyyy-MM-dd"/></td>
                                    <td>${data.scheduledTime}</td>
                                    <td>${data.reason}</td>
                                    <td>${requestScope.statusMap[data.status]}</td>
                                    <td>${data.remark}</td>
                                    <td>
                                        <button class="btn-white btn btn-xs btn-notcontrol" onclick="showData('${data.id}')"><i class="fa fa-eye"></i>&nbsp;查看</button>&nbsp;
                                    </td>
                                </tr>
                            </c:forEach>
                        </c:if>
                    </thead>
                </table>
            </div>
            <div class="formTitle">历史审批记录</div>
            <div class="tableWrap">
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <th>序号</th>
                            <th>操作人</th>
                            <th>所属公司</th>
                            <th>部门</th>
                            <th>结果</th>
                            <th>审批意见</th>
                            <th>操作时间</th>
                        </tr>
                    </thead>
                    <c:if test="${empty requestScope.taskInfoList}">
                        <tr id="nothing">
                            <td colspan="8" style="color: #bbbbbb">无审批信息</td>
                        </tr>
                    </c:if>
                    <c:if test="${not empty requestScope.taskInfoList}">
                        <c:forEach items="${requestScope.taskInfoList}" var="taskInfo" varStatus="index">
                            <tr >
                                <td>${index.count}</td>
                                <td>${taskInfo.staff_name}</td>
                                <td>${taskInfo.company_name}</td>
                                <td>${taskInfo.department_name}</td>
                                <c:if test="${taskInfo.status=='0'}">
                                    <td>驳回</td>
                                </c:if>
                                <c:if test="${taskInfo.status=='1'}">
                                    <td>同意</td>
                                </c:if>
                                <td>${taskInfo.proc_contents}</td>
                                <td>${taskInfo.proc_time}</td>
                            </tr>
                        </c:forEach>
                    </c:if>
                </table>
            </div>
            <div class="formTitle">审批</div>
            <div class="trackInfomation">
                <input id="approveProcessId" type="hidden" value="${requestScope.purchasingAudit.processInstanceId}">
                <input id="taskId" type="hidden" value="${requestScope.taskId}">
                <input id="dataCode" type="hidden" value="${requestScope.purchasingAudit.code}">
                <div class="row">
                    <div class="col-md-6">
                        <div class="form-group">
                            <span>*</span>
                            <label>审批结果：</label>
                            <input type="radio" name="result" style="width: 4%" value="1">同意
                            <input type="radio" name="result" style="width: 4%" value="0">驳回
                        </div>
                    </div>
                    <div class="col-md-12">
                        <div class="form-group">
                            <span></span>
                            <label class="fuyanText">&nbsp;&nbsp;审批意见：</label>
                            <textarea id="content" class="form-control fuyan" rows="3" placeholder="请填写审批意见"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="trackSubmit">
                <button id="submit" data-toggle="modal" data-target=".approval" onclick="approval()">审批提交</button>
                <button type="button" onclick="history.back(-1);">取消</button>
            </div>
        </div>
    </div>
</div>
<script src="css/bootstrap-3.3.7/js/jquery-2.1.4.min.js" type="text/javascript" charset="utf-8"></script>
<script src="css/bootstrap-3.3.7/js/bootstrap.js" type="text/javascript" charset="utf-8"></script>
<script>
    /**
     * 提交审批
     */
    function approval() {
        if ($('input[name = "result"]').filter(':checked').val() == null) {
            redragonJS.alert("请选择审批结果!");
            return;
        }
        $.ajax({
            type:'post',
            url : "web/approval/doPurchasingApproval",
            contentType : "application/json",
            data : JSON.stringify({
                processInstanceId : $("#approveProcessId").val(),
                taskId : $("#taskId").val(),
                dataCode : $("#dataCode").val(),
                result : $('input[name = "result"]').filter(':checked').val(),
                content : $("#content").val()
            }),
            dataType : 'json',
            async : true,
            success : function(data) {
                if(data.code == 1) {
                    redragonJS.alert("审批成功!");
                    setTimeout(function(){
                        self.location=document.referrer;
                    },1000);
                } else {
                    redragonJS.alert(data.msg);
                }
            }
        });
    }

    // 查看
    function showData(id) {
        window.location.href="web/purchasingRequisition/detail?id=" + id;
    }
</script>